package com.holly.unit.gen.starter.autoconf;



import com.holly.unit.gen.api.GenerateCodeApi;
import com.holly.unit.gen.api.config.GenCodeCfg;
import com.holly.unit.gen.starter.AutoGenerator;
import com.holly.unit.gen.starter.autoconf.prop.GenCodeExtProperties;
import com.holly.unit.gen.starter.core.AutoGenCodeCore;
import com.holly.unit.genx.GenerateCodeOperator;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 类描述: 代码生成器的自动配置
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/1/15 15:53
 */
@Configuration
public class GenCodeAutoConfiguration {

    @Bean
    @ConfigurationProperties(prefix = "gen.code.config")
    public GenCodeExtProperties genCodeExtProperties() {
        return new GenCodeExtProperties();
    }

    @Bean
    public GenerateCodeApi generateCodeApi(GenCodeExtProperties genCodeExtProperties) {
        GenCodeCfg genCodeCfg = new GenCodeCfg();
        BeanUtils.copyProperties(genCodeExtProperties,genCodeCfg);
        return new GenerateCodeOperator(genCodeCfg);
    }

    @Bean
    public AutoGenerator autoGenerator(GenerateCodeApi generateCodeApi,GenCodeExtProperties genCodeExtProperties) {
        return AutoGenerator.builder().generateCodeApi(generateCodeApi).properties(genCodeExtProperties).build();
    }

    /***
     * 支持编程模式
     * @return
     */
    @Bean
    public AutoGenCodeCore autoCodeGen() {
        return new AutoGenCodeCore();
    }

}
